import axios from '@/libs/api.request'

export const getTestcases = (params) => {
  return axios.request({
    url: 'api/HttpAutoTestService/testcases/',
    params: params,
    method: 'get'
  })
};

export const getTestcaseById = (id) => {
  return axios.request({
    url: `api/HttpAutoTestService/testcases/${id}/`,
    method: 'get'
  })
};

export const createTestcase = (data) => {
  return axios.request({
    url: 'api/HttpAutoTestService/testcase/',
    data: data,
    method: 'post'
  })
};

export const updateTestcase = (testcase) => {
  return axios.request({
    url: `api/HttpAutoTestService/testcase/${testcase.id}/`,
    data: testcase,
    method: 'put'
  })
};

export const partialUpdateTestcase = (testcase) => {
  let id = testcase.id;
  delete testcase.id;
  return axios.request({
    url: `api/HttpAutoTestService/testcase/${id}/`,
    data: testcase,
    method: 'patch'
  })
};

export const batchDeleteTestcase = (data) => {
  return axios.request({
    url: 'api/HttpAutoTestService/testcase/batch_delete/',
    method: 'delete',
    data: data
  })
};

export const debugTestcase = (data) => {
  return axios.request({
    url: 'api/HttpAutoTestService/testcase/debug/',
    data: data,
    method: 'post'
  })
};

export const batchExecTestcase = (data) => {
  return axios.request({
    url: 'api/HttpAutoTestService/testcase/batch_exec/',
    method: 'post',
    data: data
  })
};

export const downloadTestcaseTemplate = () => {
  return axios.request({
    url: 'api/HttpAutoTestService/testcase/template/download/',
    method: 'get',
    responseType: 'arraybuffer'
  })
};

export const uploadTestcaseFile = (data) => {
  return axios.request({
    url: 'api/HttpAutoTestService/testcase/upload/',
    method: 'post',
    data: data
  })
};

export const batchCreateTestcase = (data) => {
  return axios.request({
    url: 'api/HttpAutoTestService/testcase/batch_create/',
    method: 'post',
    data: data
  })
};